package scaladay2

object YieldDemo {
  def main(args: Array[String]): Unit = {
    val arr = Array(1, 2 , 3, 4, 5, 6, 7)
    val res = for(e <- arr) yield  e*2
    println(res.toBuffer)
    println(arr.map((x:Int) => x*2).toBuffer)
    println(arr.map((x) => x*2).toBuffer)
    println(arr.map(x => x*2).toBuffer)
    println(arr.map(_*2).toBuffer)

    println(arr.filter((x:Int) => x % 2 == 0).toBuffer)
    println(arr.filter((x) => x % 2 == 0).toBuffer)
    println(arr.filter(x => x % 2 == 0).toBuffer)
    println(arr.filter(_ % 2 == 0).toBuffer)

    println(arr.filter(_ % 2 == 0).map(_*2).toBuffer)


    println(arr.max)
    println(arr.min)
    println(arr.sum)

    val ints: Array[Int] = Array(11, 2 , 13, 4, 51)
    println(ints.reduce((x:Int, y:Int) => x+y))
    println(ints.reduce((x, y) => x+y))
    println(ints.reduce(_+_))

    println(ints.sorted.toBuffer)
    println(ints.sortWith((x:Int, y:Int)=> x>y).toBuffer)
    println(ints.sortBy((x:Int)=>x).toBuffer)
    println(ints.sortBy(_*1).toBuffer)
    println(ints.sortBy((x:Int)=>x + "").toBuffer)
    println(ints.sortBy((x)=>x + "").toBuffer)
    println(ints.sortBy(_ + "").toBuffer)


  }
}
